

import Mock from "mockjs"
import { ref, type Ref } from "vue"


const ver: Ref<string> = ref(Mock.mock('@string("number", 6)'))

const { commundata } = Mock.mock({
    'commundata|20': [{
        flog: false,
        id: '@cname',
        time: '@date',
        title: '@csentence',
        photo: '@image(200x100 ,@color , Mock)',
        img1: '@image(200x100 ,@color ,Hello Mock.js!)',
        img2: '@image(200x100 ,@color ,Hello Mock.js!)',
        img3: '@image(200x100 ,@color ,Hello Mock.js!)',
        'share|1-100': 12,
        'chat|1-100': 20,
        starflog: false,
    }]
})

let collist: any = []

Mock.mock('/api/verification', 'post', (config: any) => {

    console.log(config);

    return {
        code: 200,
        message: '验证码请求成功',
        num: ver.value
    }
})


Mock.mock('/api/community', 'post', (config: any) => {


    return {
        code: 200,
        message: '请求成功',
        data: commundata
    }
})



Mock.mock('/api/addcommunity', 'post', (config: any) => {

    console.log(1111, config);
    commundata.unshift(JSON.parse(config.body))
    return {
        code: 200,
        message: '请求成功',
        data: commundata
    }
})



Mock.mock('/api/deletcommunity', 'post', (config: any) => {

    console.log(1111, config);
    commundata.splice(config.body, 1)

    return {
        code: 200,
        message: '请求成功',
        data: commundata
    }
})

Mock.mock('/api/modcommunity', 'post', (config: any) => {
    console.log('mock', config.body);
    return {
        code: 200,
        message: '请求成功',
        data: commundata[config.body]
    }

})

Mock.mock('/api/changecommunity', 'post', (config: any) => {
    const iconfig = JSON.parse(config.body)
    console.log();

    commundata[iconfig.index].title = iconfig.title
    commundata[iconfig.index].img1 = iconfig.img1
    commundata[iconfig.index].img2 = iconfig.img2
    commundata[iconfig.index].img3 = iconfig.img3
    commundata[iconfig.index].time = iconfig.time

    return {
        code: 200,
        message: '请求成功',
        data: commundata[config.body]
    }

})


// 收藏
Mock.mock('/api/collection', 'post', (config: any) => {

    const iconfig = JSON.parse(config.body)
    console.log(1.1);

    console.log('config', iconfig);
    commundata[iconfig.index].starflog = iconfig.starflog._value

    if (iconfig.starflog._value == true) {


        collist.push(commundata[iconfig.index])
        console.log(1.2);


    } else {

        collist.splice(iconfig.index)

        collist.forEach((item: any, index: number) => {

            if (item == commundata[iconfig.index]) {
                collist.splice(index, 1)
            }

        });

    }


    console.log(collist);


    return {
        code: 200,
        message: '请求成功,返回收藏列表',
        data: collist
    }

})


//删除收藏



// 弹幕
const { danmu } = Mock.mock({
    'danmu|20': ['@csentence']
})

Mock.mock('/api/danmu', 'post', () => {

    return {
        code: 200,
        message: '请求成功',
        data: danmu
    }

})













